﻿Public Class MASBILLING
    Private BILLID As Integer = Nothing
    Private BNAME_TH As String = Nothing
    Private BNAME_EN As String = Nothing
    Private STATUS = Nothing
    Private SelectMasbilling = "SELECT `billid` as  'รหัส',`bname_th` as 'ชื่อลำดับใบเสร็จภาษาไทย',`bname_en` as 'ชื่อลำดับใบเสร็จภาษาอังกฤษ' ,`status` as 'สถานะการเปิดใช้งาน' FROM masbilling "
    Dim connect As CONDB = CONDB.NewConnection
    Property BILLID_() As Integer
        Get
            Return BILLID
        End Get
        Set(value As Integer)
            BILLID = value
        End Set
    End Property
    Property BNAME_TH_() As String
        Get
            Return BNAME_TH
        End Get
        Set(value As String)
            BNAME_TH = value
        End Set
    End Property
    Property BNAME_EN_() As String
        Get
            Return BNAME_EN
        End Get
        Set(value As String)
            BNAME_EN = value
        End Set
    End Property
    Property STATUS_() As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property
    Property SelectMasbilling_() As String
        Get
            Return SelectMasbilling
        End Get
        Set(value As String)

        End Set
    End Property
    Public Sub insertMasbillingData()
        If TypeOf BNAME_TH Is String And TypeOf BNAME_EN_ Is String Then
            If connect.GetTable("SELECT `bname_th` FROM MASBILLING WHERE  `bname_th` = '" & BNAME_TH & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลส่วนนี้อยู่ในระบบแล้ว", MsgBoxStyle.Critical)
            Else
                connect = CONDB.NewConnection()
                connect.BeginTrans()
                Try
                    Dim sql As String
                    sql = "INSERT INTO masbilling"
                    sql += "(`bname_th`,`bname_en`,`status`)"
                    sql += "VALUES ("
                    sql += "'" & BNAME_TH & "',"
                    sql += "'" & BNAME_EN & "',"
                    sql += "'" & STATUS & "')"
                    connect.ExecuteNonQuery(sql)
                    connect.CommitTrans()
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
                Catch ex As Exception
                    connect.RollbackTrans()
                    MsgBox(ex.ToString)
                Finally
                    connect.Dispose()
                End Try
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub
    Public Sub editMasbillingData()
        If TypeOf BNAME_TH Is String And TypeOf BNAME_EN_ Is String Then
            connect = CONDB.NewConnection()
            connect.BeginTrans()
            Try
                Dim sql As String
                sql = "UPDATE masbilling SET"
                sql += "`bname_th` = '" & BNAME_TH & "',"
                sql += "`bname_en` = '" & BNAME_EN & "',"
                sql += "`status` = '" & STATUS & "' "
                sql += "WHERE `billid` = '" & BILLID & "';"
                connect.ExecuteNonQuery(sql)
                connect.CommitTrans()
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            Finally
                connect.Dispose()
            End Try
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub
End Class
